package com.cucheng.chatroom.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cucheng.chatroom.model.vo.ResponseJson;
import com.cucheng.chatroom.service.SecurityService;

@Controller
public class SecurityController {

    @Autowired
    SecurityService securityService;

    @RequestMapping(value = { "login", "/" },method = RequestMethod.GET)
    public String toLogin(){
        return "login";
    }

    /**
     *@Description: TODO(用户登录) 
     *@Author: wangchengjie
     *@Since: 2019年3月30日下午3:48:21
     *@param session
     *@param username
     *@param password
     *@return
     */
    @RequestMapping(value = "login",method = RequestMethod.POST)
    @ResponseBody
    public ResponseJson login(HttpSession session,@RequestParam String username,@RequestParam String password){
        return securityService.login (username, password, session);
    }

    /**
     *@Description: TODO(用户退出) 
     *@Author: wangchengjie
     *@Since: 2019年3月30日下午3:48:32
     *@param session
     *@return
     */
    @RequestMapping(value = "logout",method = RequestMethod.POST)
    @ResponseBody
    public ResponseJson logout(HttpSession session){
        return securityService.logout (session);
    }
}
